package com.xkcyy.one.controller;

import cn.hutool.core.util.StrUtil;
import com.xkcyy.one.ai.llm.OpenAiClient;
import com.xkcyy.one.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * 示例Controller
 *
 * @author AI Assistant
 */
@Tag(name = "示例接口", description = "用于展示Swagger注解的使用方式")
@RestController
@RequestMapping("/api/demo")
public class DemoController {



    @Autowired
    OpenAiClient openAiClient;
    @Operation(summary = "获取欢迎信息", description = "返回一个简单的欢迎信息")
    @GetMapping(path = "/hello", produces = MediaType.TEXT_EVENT_STREAM_VALUE+ ";charset=UTF-8")
    public Flux<String> hello() {
        return openAiClient.chatStream("你叫什么名字？").map(x->{
            return StrUtil.isEmpty(x.getContent())?x.getReasoningContent():x.getContent();
        });

    }

    @Operation(summary = "回显消息", description = "将传入的消息返回给调用者")
    @PostMapping("/echo")
    public Result<String> echo(
            @Parameter(description = "要回显的消息内容") 
            @RequestParam String message
    ) {
        return Result.success(message);
    }
}